class Watcher {
  constructor() {
    this.subs = {};
  }

  $on(type, fn) {
    this.subs[type] = this.subs[type] || [];
    this.subs[type].push(fn);
  }

  $notify(type) {
    this.subs[type].forEach(fn => {
      fn();
    })
  }

  $clear(type) {
    this.subs[type] = [];
  }
}

export default Watcher;